package com.xiyuan.smartutils.template.engine;

import com.xiyuan.smartutils.template.engine.statement.*;

/****
 * 标签类型定义
 *
 * @version v1.0.0 @author lgz 2021-1-21 新建与整理
 */
public enum TagType {
    /***文本标签*/
    TEXT {
        @Override
        public _Text newStatement(StatementParser parser) {
            return new _Text(parser);
        }
        
        @Override
        public String getName() {
            return "TEXT";
        }
        
        @Override
        public String getTagBegin() {
            return "";
        }
        
        @Override
        public String getTagEnd() {
            return "";
        }
        
        @Override
        public String getTagComplete() {
            return "";
        }
    },
    /**
     * block 块
     */
    BLOCK() {
        @Override
        public String getName() {
            return "<#block>";
        }
        
        @Override
        public String getTagBegin() {
            return "<#block";
        }
        
        @Override
        public String getTagEnd() {
            return BLOCK_END.getName();
        }
        
        @Override
        public String getTagComplete() {
            return ">";
        }
        
        @Override
        public Statement newStatement(StatementParser parser) {
            return new _BLOCK(parser);
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
    },
    BLOCK_END {
        @Override
        public TagType beginTag() {
            return BLOCK;
        }
        
        @Override
        public _BLOCK_END newStatement(StatementParser parser) {
            return new _BLOCK_END(parser);
        }
        
        @Override
        public boolean isBlockEnd() {
            return true;
        }
        
        @Override
        public String getName() {
            return "</#block>";
        }
        
        @Override
        public String getTagBegin() {
            return "</#block";
        }
        
        @Override
        public String getTagEnd() {
            return ">";
        }
        
        @Override
        public String getTagComplete() {
            return getTagEnd();
        }
        
        
    },
    /**
     * 属性取值，如：${attrName}
     */
    ECHO() {
        @Override
        public _Echo newStatement(StatementParser parser) {
            return new _Echo(parser);
        }
        
        public String getName() {
            return "${}";
        }
        
        public String getTagBegin() {
            return "${";
        }
        
        public String getTagEnd() {
            return "}";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    // /**函数调用;如：@{System.out.println("hello word")}*/
    CALL() {
        @Override
        public _Call newStatement(StatementParser parser) {
            return new _Call(parser);
        }
        
        public String getName() {
            return "@{}";
        }
        
        public String getTagBegin() {
            return "@{";
        }
        
        public String getTagEnd() {
            return "}";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    /**
     * 格式化属性取值，如：#{attrName}
     */
    ECHO_FORMAT() {
        @Override
        public _Echo_Format newStatement(StatementParser parser) {
            return new _Echo_Format(parser);
        }
        
        public String getName() {
            return "#{}";
        }
        
        public String getTagBegin() {
            return "#{";
        }
        
        public String getTagEnd() {
            return "}";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    /**
     * java 代码注释，如：<#-- 这是注释内容 -->
     */
    COMMENT() {
        @Override
        public _Text newStatement(StatementParser parser) {
            return new _Text(parser);
        }
        
        public String getName() {
            return "<#--  -->";
        }
        
        public String getTagBegin() {
            return "<#--";
        }
        
        public String getTagEnd() {
            return "-->";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    
    /**
     * 页面嵌入，如：<#include src="./abc.html"/>
     */
    INCLUDE() {
        @Override
        public _INCLUDE newStatement(StatementParser parser) {
            return new _INCLUDE(parser);
        }
        
        public String getName() {
            return "<#include/>";
        }
        
        public String getTagBegin() {
            return "<#include";
        }
        
        public String getTagEnd() {
            return "/>";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    /**函数定义定义，如：<#function testMethod(a,b,b)>，结束标签为：</#function>*/
    /**
     * 变量定义，如：<#var a = "abc"/>
     */
    VAR() {
        @Override
        public _Var newStatement(StatementParser parser) {
            return new _Var(parser);
        }
        
        public String getName() {
            return "<#var/>";
        }
        
        public String getTagBegin() {
            return "<#var";
        }
        
        public String getTagEnd() {
            return "/>";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    
    /**
     * if条件，如：<#if a gt 0>，结束标签为</#if>
     */
    FUNCTION() {
        @Override
        public _FUNCTION newStatement(StatementParser parser) {
            return new _FUNCTION(parser);
        }
        
        public String getName() {
            return "<#function>";
        }
        
        public String getTagBegin() {
            return "<#function";
        }
        
        public String getTagEnd() {
            return FUNCTION_END.getName();
        }
        
        public String getTagComplete() {
            return ">";
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
    },
    FUNCTION_END {
        @Override
        public TagType beginTag() {
            return FUNCTION;
        }
        
        @Override
        public _FUNCTION_END newStatement(StatementParser parser) {
            return new _FUNCTION_END(parser);
        }
        
        @Override
        public boolean isBlockEnd() {
            return true;
        }
        
        @Override
        public String getName() {
            return "</#function>";
        }
        
        @Override
        public String getTagBegin() {
            return "</#function";
        }
        
        @Override
        public String getTagEnd() {
            return ">";
        }
        
        @Override
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    IF() {
        @Override
        public _IF newStatement(StatementParser parser) {
            return new _IF(parser);
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
        
        public String getName() {
            return "<#if>";
        }
        
        public String getTagBegin() {
            return "<#if";
        }
        
        public String getTagEnd() {
            return END_IF.getName();
        }
        
        public String getTagComplete() {
            return ">";
        }
    },
    /**
     * if条件，如：<#elseif a gt 0>，结束标签为<#if>结束标签
     */
    ELSEIF() {
        @Override
        public _IF_ELSE_IF newStatement(StatementParser parser) {
            return new _IF_ELSE_IF(parser);
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
        
        public String getName() {
            return "<#elseif>";
        }
        
        public String getTagBegin() {
            return "<#elseif";
        }
        
        public String getTagEnd() {
            return IF.getTagEnd();
        }
        
        public String getTagComplete() {
            return ">";
        }
    },
    /**
     * if条件，如：<#else>，结束标签为<#if>结束标签
     */
    ELSE() {
        @Override
        public _IF_ELSE newStatement(StatementParser parser) {
            return new _IF_ELSE(parser);
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
        
        public String getName() {
            return "<#else>";
        }
        
        public String getTagBegin() {
            return "<#else";
        }
        
        public String getTagEnd() {
            return IF.getTagEnd();
        }
        
        public String getTagComplete() {
            return ">";
        }
    },
    END_IF {
        @Override
        public TagType beginTag() {
            return IF;
        }
        
        @Override
        public _IF_END newStatement(StatementParser parser) {
            return new _IF_END(parser);
        }
        
        @Override
        public boolean isBlockEnd() {
            return true;
        }
        
        @Override
        public String getName() {
            return "</#if>";
        }
        
        @Override
        public String getTagBegin() {
            return "</#if";
        }
        
        @Override
        public String getTagEnd() {
            return ">";
        }
        
        @Override
        public String getTagComplete() {
            // TODO Auto-generated method stub
            return null;
        }
    },
   
    /**
     * for条件下continue，如：<#continue/>
     */
    CONTINUE() {
        @Override
        public _Continue newStatement(StatementParser parser) {
            return new _Continue(parser);
        }
        
        public String getName() {
            return "<#continue/>";
        }
        
        public String getTagBegin() {
            return "<#continue";
        }
        
        public String getTagEnd() {
            return "/>";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    /**
     * for条件下break，如：<#break/>
     */
    BREAK() {
        @Override
        public _Break newStatement(StatementParser parser) {
            return new _Break(parser);
        }
        
        public String getName() {
            return "<#break/>";
        }
        
        public String getTagBegin() {
            return "<#break";
        }
        
        public String getTagEnd() {
            return "/>";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },
    /**
     * function下return语句，如：<#return/>， 或者 <#return "a"/> 或者 <#return list.get(0)/>
     */
    RETURN() {
        @Override
        public _RETURN newStatement(StatementParser parser) {
            return new _RETURN(parser);
        }
        
        public String getName() {
            return "<#return/>";
        }
        
        public String getTagBegin() {
            return "<#return";
        }
        
        public String getTagEnd() {
            return "/>";
        }
        
        public String getTagComplete() {
            return getTagEnd();
        }
    },

    /**
     * for条件，如：<#for a:list>，结束标签为</#for>
     */
    FOR() {
        @Override
        public _FOR newStatement(StatementParser parser) {
            return new _FOR(parser);
        }
        
        @Override
        public boolean isBlockTag() {
            return true;
        }
        
        public String getName() {
            return "<#for>";
        }
        
        public String getTagBegin() {
            return "<#for";
        }
        
        public String getTagEnd() {
            return FOR_END.getName();
        }
        
        public String getTagComplete() {
            return ">";
        }
    },
    FOR_END {
        @Override
        public TagType beginTag() {
            return FOR;
        }
        
        @Override
        public _FOR_END newStatement(StatementParser parser) {
            return new _FOR_END(parser);
        }
        
        @Override
        public String getName() {
            return "</#for>";
        }
        
        @Override
        public String getTagBegin() {
            return "</#for";
        }
        
        @Override
        public String getTagEnd() {
            return ">";
        }
        
        @Override
        public String getTagComplete() {
            return getTagEnd();
        }
        
        @Override
        public boolean isBlockEnd() {
            return true;
        }
    },
    //
    ;
    
    /***获取标签全称*/
    public abstract String getName();
    
    /***获取开始标签字符串*/
    public abstract String getTagBegin();
    
    /***获取标签结束字符串*/
    public abstract String getTagEnd();
    
    /***开始标签就绪字符串*/
    public abstract String getTagComplete();
    
    public abstract Statement newStatement(StatementParser parser);
    
    /**
     * 获取标签开始类，主要针对块标签的结束标签，其他标签返回this
     */
    public TagType beginTag() {
        return this;
    }
    
    ;
    
    /***是否为块标签*/
    public boolean isBlockTag() {
        return false;
    }
    
    /***是否为结束快标签*/
    public boolean isBlockEnd() {
        return false;
    }
    
    public String toString() {
        return this.getName();
    }
    
    ;
}
